package org.wmq.housewebadmin.service.impl;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.wmq.housemodel.entity.PaymentType;
import org.wmq.housemodel.entity.Result;
import org.wmq.housewebadmin.mapper.PaymentTypeMapper;
import org.wmq.housewebadmin.service.PaymentTypeService;

import java.util.List;

@Service
@RequiredArgsConstructor
public class PaymentTypeServiceImpl implements PaymentTypeService {
    private final PaymentTypeMapper paymentTypeMapper;

    @Override
    public List<PaymentType> getPaymentTypeList() {
        return this.paymentTypeMapper.selectAll();
    }

    @Override
    public Result<Void> saveOrUpdatePaymentType(PaymentType paymentType) {
        if (paymentType.getId() == null){
            if (this.paymentTypeMapper.insert(paymentType) == 0){
                return Result.error("id已存在");
            }else{
                return Result.ok();
            }
        }else{
            if (this.paymentTypeMapper.updateById(paymentType) == 0){
                return Result.error("id不存在");
            }else{
                return Result.ok();
            }
        }

    }

    @Override
    public boolean deletePaymentTypeById(Long id) {
        PaymentType paymentType = new PaymentType();
        paymentType.setId(id);
        return this.paymentTypeMapper.deleteById(paymentType) == 1;
    }
}
